package fr.teuteuf.runstickmanrun.map.block;

import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.physics.box2d.World;

import fr.teuteuf.runstickmanrun.map.MapGenerator;
import fr.teuteuf.runstickmanrun.map.tile.SolidBoxTile;
import fr.teuteuf.runstickmanrun.map.tile.Tile;

public class SplitStairsBlock extends AbstractMapBlock {
	
	public SplitStairsBlock(int difficultyLevel) {
		setDifficulties(2, 3, 7);
		setCurrentLevel(difficultyLevel);
	}

	@Override
	public int generateBlock(World world, MapGenerator mg, int nbHorizontalTiles) {
		int blockLength = 0;
		int stairsNumber = MathUtils.random(3, 14);
		int gapSize = MathUtils.random(1, 3);
		
		while(blockLength < stairsNumber) {
			if(getCurrentLevel() < getMaxDifficultyLevel()) {
				mg.addTile(new SolidBoxTile((byte) 9, 0, 1, (nbHorizontalTiles + blockLength) * Tile.TILE_SIZE, (blockLength + 1) * Tile.TILE_SIZE, world));
				buildBlockColumn(0, (byte) 8, (nbHorizontalTiles + blockLength), blockLength, 0, 1, 2, world, mg);
				blockLength++;
			} else {
				mg.addTile(new SolidBoxTile((byte) 11, 7, 1, (nbHorizontalTiles + blockLength) * Tile.TILE_SIZE, (blockLength + 1) * Tile.TILE_SIZE, world));
				buildBlockColumn(0, (byte) 10, (nbHorizontalTiles + blockLength), blockLength, 0, 1, 2, world, mg);
				blockLength++;
			}
			
			if(getCurrentLevel() < getMedDifficultyLevel()) {
				mg.addTile(new SolidBoxTile((byte) 9, 0, 1, (nbHorizontalTiles + blockLength) * Tile.TILE_SIZE, (blockLength + 1) * Tile.TILE_SIZE, world));
				buildBlockColumn(0, (byte) 0, (nbHorizontalTiles + blockLength), blockLength, 0, 1, 2, world, mg);
				blockLength++;
			}
			
			if(getCurrentLevel() < getMaxDifficultyLevel()) {
				mg.addTile(new SolidBoxTile((byte) 11, 7, 1, (nbHorizontalTiles + blockLength) * Tile.TILE_SIZE, (blockLength + 1) * Tile.TILE_SIZE, world));
				buildBlockColumn(0, (byte) 2, (nbHorizontalTiles + blockLength), blockLength, 0, 1, 2, world, mg);
				blockLength++;
			}
			
			blockLength += gapSize;
		}
		
		return nbHorizontalTiles + blockLength;
	}

}
